<?php

namespace api\admin\controller;

class AdminRoleController extends \Aaa\admin\controller\AdminRoleController {
    public $baseField = [
        [
            'field' => 'id',
            'name' => 'ID',
        ],
        [
            'field' => 'name',
            'name' => '角色名称',
            'placeholder' => '请输入角色名称'
        ],
        [
            'field' => 'remark',
            'name' => '备注',
            'placeholder' => '请输入备注'
        ],
        [
            'field' => 'privilege',
            'name' => '权限',
            'type' => 'tree',
            'expanded' => true,
        ],
    ];

    protected function beforeIndex() {
        $this->actionField = ['id', 'name', 'remark'];
        $this->searchField = [
            'common' => [
                'name' => 'fuzzy',
                'remark' => 'fuzzy',
            ],
        ];
    }

    protected function beforeAdd() {
        $this->actionField = ['name', 'remark', 'privilege'];
    }

    protected function beforeEdit() {
        $this->beforeAdd();
    }

    protected function beforeEditPost() {
        if (is_array($this->paramId)) {
            $this->error('超级管理员角色禁止修改', !in_array(1, $this->paramId));
        } else {
            $this->error('超级管理员角色禁止修改', $this->paramId != 1);
        }
    }

    protected function beforeDeletePost() {
        if (is_array($this->paramId)) {
            $this->error('超级管理员角色禁止删除', !in_array(1, $this->paramId));
        } else {
            $this->error('超级管理员角色禁止删除', $this->paramId != 1);
        }
    }

}
